package com.niit.musicserve.utils;

import lombok.Data;

@Data
public class Result<T> {
	
	//登录名
	private String name;
	//状态码
	private String code;
	//返回信息
	private String msg;
	//token
	private String token;
	//返回数据
	private T data;
	
	public static <T> Result<T> success(){
		
		Result<T> result = new Result<>();
		result.code = "1";
		result.msg = "操作成功";
		return result;
	}
	
	public static <T> Result<T> success(T data){
		
		Result<T> result = new Result<>();
		result.code = "1";
		result.msg = "操作成功";
		result.data = data;
		return result;
	}
	
	public static <T> Result<T> success(String  msg,T data){
		
		Result<T> result = new Result<>();
		result.code = "1";
		result.msg = msg;
		result.data = data;
		return result;
	}
	
	public static <T> Result<T> success(String name,String token,T data){
		
		Result<T> result = new Result<>();
		result.name = name;
		result.code = "1";
		result.data = data;
		result.token = token;
		return result;
	}
	
	public static <T> Result<T> error(String msg){
		
		Result<T> result = new Result<>();
		result.code = "0";
		result.msg = msg;
		return result;
	}
	
	public static <T> Result<T> successWithToken(String msg, String token, T data){
		Result<T> result = new Result<>();
		result.code = "200";
		result.msg = msg;
		result.token = token;
		result.data = data;
		return result;
	}
}
